package com.example.demo.api;

import com.example.demo.dto.request.UserQueryReq;
import com.example.demo.entity.Msg;
import com.example.demo.util.QueryBeanUtils;
import com.example.demo.util.ValidationUtil;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


/**
 * @author 陈浩
 * @date 2021/1/8 9:53
 */
@Api(tags = "测试接口")
@AllArgsConstructor
@RestController
public class TestController {

    @GetMapping("/get")
    @ApiOperationSupport(author = "陈浩")
    @ApiOperation(value = "测试接口", response = UserQueryReq.class)
    @ApiImplicitParams(value = {
            @ApiImplicitParam(value = "用户姓名", name = "name", paramType = "query"),
            @ApiImplicitParam(value = "年龄", name = "age", paramType = "query")
        }
    )
    public Msg test(HttpServletRequest request) throws Exception {
        UserQueryReq u =  QueryBeanUtils.mapToObject(request, UserQueryReq.class);
        ValidationUtil.validateBean(u);

        return Msg.builder()
                .msg("123")
                .item(u)
                .build();
    }


}
